using System;
using System.Diagnostics;
using System.Linq.Expressions;

namespace CustomORM.Examples.Helpers
{
    public class MeasureExecTime
    {
        public class MethodExecutionResults
        {
            public long EllapsedMilliseconds { get; set; }
            public object Result { get; set; }
        }

        public static MethodExecutionResults ExecTest(Expression<Func<object>> expression)
        {
            var stopwatch = new Stopwatch();
            stopwatch.Start();
            var result = expression.Compile().Invoke();
            stopwatch.Stop();
            var methodExecutionResults = new MethodExecutionResults() { EllapsedMilliseconds = stopwatch.ElapsedMilliseconds, Result = result };
            return methodExecutionResults;
        }
    }
}